<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:tiles="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" >
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <!--<link rel="stylesheet" href="/css/app.css">-->
    <!--<link rel="stylesheet" href="/css/zui.min.css" />-->
    <link rel="stylesheet" href="/css/default.css" />
    <link rel="stylesheet" href="/css/ui.jqgrid-bootstrap.css" />
    <script>
        if (typeof module === 'object') {
            window.module = module;
            module = undefined;
        }
    </script>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/js/jquery-ui.min.js"></script>

    <script type="text/javascript" src="/js/jquery.cookie.js"></script>
    <script>
        console.log(window.module);
        if (window.module) {
            module = window.module;
        }
    </script>
    <title>用户登陆</title>

	<script type="text/javascript">

		$(function() {
            var username = $.cookie('cookie_user');
            var userpassword = $.cookie('cookie_password');
            var remember_me = $.cookie('remember_me');
            console.log(remember_me);
            $(window).on('load',function(){
                if(!username){
                    $('#user_name').val("");
                    $('#user_password').val("");
                }else{
                    $('#user_name').val(username);
                    $('#user_password').val(userpassword);
                }
            });

            $("#login_btn").bind("click", function() {
                var user_name = $("#user_name").val();
                if(user_name.length==0){
                    alert("请输入工号/用户名/手机号");
                    return ;
                }
                var data = {
                    username: user_name,
                    password: $("#user_password").val(),
                    remember: $("#remember").prop("checked"),
                };
                console.log(data);
                $.ajax("/login", {
                    data: JSON.stringify(data),//$(this).serialize(), // serializes the form's elements.
                    type: "post",
                    contentType: 'application/json',
                }).done(function(data) {
                            if (data.valid) {
                                self.location.href = data.url || '/admin/menu';
                            } else {
                                alert(data.errorMsg);
                            }
                });
            });
        });

	</script>
</head>

<body>
    <div class="login_div">
        <form id="loginForm" class="login_form" action="/login" method="post">
                <table>
                    <tbody>
                    <tr><td><span style="font-weight: bolder;font-size: larger">智慧餐饮管理系统</span></td></tr>
                    <tr>
                        <td>
                            <input type="text" id="user_name" name="username" autocomplete="off" class="form-control" placeholder="工号">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="password" id="user_password" name="password" autocomplete="off" class="form-control" placeholder="密码">
                        </td>
                    </tr>
                    <tr style="margin-bottom: 0px">
                        <!--<td colspan="2" style="text-align: left">-->
                        <td style="text-align: left">
                            <input id="remember" type="checkbox" name="remember" checked> 记住我
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input  type="button" id="login_btn" class="btn_login" value=" 登陆 " />
                        </td>
                    </tr>
                    </tbody>
                </table>
        </form>
    </div>
</body>

</html>